{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "45e9e951",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['珍珠奶茶小杯', 6], ['椰果奶茶中杯', 7], ['芝士奶盖大杯', 8], ['芋圆啵啵奶茶', 14], ['杨枝甘露', 8]]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. 商品列表\n",
    "goods_list = [\n",
    "    ['珍珠奶茶小杯',6],\n",
    "    ['椰果奶茶中杯',7],\n",
    "    ['芝士奶盖大杯',8],\n",
    "    ['芋圆啵啵奶茶',14],\n",
    "    ['杨枝甘露',8]\n",
    "]\n",
    "goods_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "21a679f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# goods_list[0]是不是一个列表\n",
    "goods_list[0][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "374abf70",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的账户余额：100\n",
      "-----------商品列表----------\n",
      "商品编号：0 ,商品名称：珍珠奶茶, 商品价格：6\n",
      "商品编号：1 ,商品名称：奶盖四季柠檬茶, 商品价格：8\n",
      "商品编号：2 ,商品名称：杨枝甘露, 商品价格：7\n",
      "商品编号：3 ,商品名称：圣代, 商品价格：6\n",
      "商品编号：4 ,商品名称：多肉葡萄, 商品价格：10\n",
      "请输入你要购买的商品编号（输入‘q’退出购买）：q\n",
      "-----------购物车----------\n",
      "您的购物车为【[]】,您的余额还有【100】\n"
     ]
    }
   ],
   "source": [
    "# 商品信息：列表数据\n",
    "# goods_list[int(choice)] 用户输入之后选择的商品信息\n",
    "goods_list = [\n",
    "    ['珍珠奶茶',6],\n",
    "    ['奶盖四季柠檬茶',8],\n",
    "    ['杨枝甘露',7],\n",
    "    ['圣代',6],\n",
    "    ['多肉葡萄',10]\n",
    "]\n",
    "\n",
    "# 用户购物车信息：列表数据\n",
    "user_shopping_cart = []\n",
    "\n",
    "# 用户输入\n",
    "Alipay = int(input('请输入您的账户余额：'))\n",
    "\n",
    "# 打印商品信息\n",
    "# ---------\n",
    "# 商品编号：%s ,商品名称：%s, 商品价格：%s\n",
    "# 商品编号：%s ,商品名称：%s, 商品价格：%s\n",
    "\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(0,goods_list[0][0],goods_list[0][1]))\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(1,goods_list[1][0],goods_list[1][1]))\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(2,goods_list[2][0],goods_list[2][1]))\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(3,goods_list[3][0],goods_list[3][1]))\n",
    "# print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(4,goods_list[4][0],goods_list[4][1]))\n",
    "while True: # 考虑什么时候退出\n",
    "    print(\"-----------商品列表----------\")\n",
    "    for i in range(len(goods_list)):\n",
    "        print(\"商品编号：%s ,商品名称：%s, 商品价格：%s\"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "\n",
    "    choice = input(\"请输入你要购买的商品编号（输入‘q’退出购买）：\") # 1. 输入编号数字  2. 输入“q”3. 输入的啥也不是！\n",
    "    if choice.isdigit():\n",
    "        if int(choice)>=0 and int(choice)<len(goods_list):\n",
    "        # 一、数字 在 列表范围内\n",
    "            # 1. 输入编号数字 数值应该在 商品列表范围以内 \n",
    "            # 判断1 ： Alipay  VS  goods_list[choice][1]（商品价格）   goods_list[int(choice)] (用户输入之后选择的商品信息)\n",
    "            if Alipay >= goods_list[int(choice)][1]:\n",
    "                # 1. Alipay重新赋值\n",
    "                Alipay = Alipay - goods_list[int(choice)][1] # 扣钱\n",
    "                print(\"\\n你点的【%s】已经购买成功，请等候~，您的余额还有【%s】元\\n\"%(goods_list[int(choice)][0],Alipay))\n",
    "                user_shopping_cart.append(goods_list[int(choice)] ) # 增加用户选择的商品信息\n",
    "            else:\n",
    "                print(\"\\n你的钱包不够啊，换种方式支付吧~\\n\")\n",
    "        else:\n",
    "        # 二、数字 不在 列表范围内\n",
    "            print(\"您输入的商品不存在，请输入正确的商品编码（输入‘q’退出购买）：\")\n",
    "    elif choice == \"q\":\n",
    "        # 2. 输入“q”\n",
    "        print(\"-----------购物车----------\")\n",
    "        print(\"您的购物车为【%s】,您的余额还有【%s】\"%(user_shopping_cart,Alipay))\n",
    "        break    \n",
    "    else:\n",
    "        # 3.  输入的啥也不是！不符合要求\n",
    "        print(\"**您输入的内容不符合要求，请检查重新输入！**\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "eb1f2d2a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 珍珠奶茶小杯 6\n",
      "1 椰果奶茶中杯 7\n",
      "2 芝士奶盖大杯 8\n",
      "3 芋圆啵啵奶茶 14\n",
      "4 杨枝甘露 8\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i,goods_list[i][0],goods_list[i][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9f55485c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(goods_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "825f8ea8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "商品编号：0 ，商品名称:珍珠奶茶小杯 , 商品价格：6\n",
      "商品编号：1 ，商品名称:椰果奶茶中杯 , 商品价格：7\n",
      "商品编号：2 ，商品名称:芝士奶盖大杯 , 商品价格：8\n",
      "商品编号：3 ，商品名称:芋圆啵啵奶茶 , 商品价格：14\n",
      "商品编号：4 ，商品名称:杨枝甘露 , 商品价格：8\n"
     ]
    }
   ],
   "source": [
    "# 思考：如果增加商品了，或者下架商品了 5 是不是变了？\n",
    "#        5 是什么？---->\n",
    "for i in range(5):\n",
    "    print(\"商品编号：%s ，商品名称:%s , 商品价格：%s\"%(i,goods_list[i][0],goods_list[i][1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aac74f17",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
